package org.dtrd.modules.evaluation.entity.bean;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.dtrd.modules.evaluation.constant.Evaluation;
import org.dtrd.modules.evaluation.entity.po.DtrdEntEvaluationRdSleep;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author QR
 * @Date 2021/11/1 1:46 PM
 */
@ApiModel("匹兹堡睡眠质量评估")
@Data
public class SleepInfo {

    @ApiModelProperty("记录id")
    private Integer dataId;

    @ApiModelProperty("患者id")
    private Integer patientId;

    @ApiModelProperty("分值列表")
    private List<Integer> input;

    @ApiModelProperty("总分")
    private Integer total;

    @ApiModelProperty("睡眠等级")
    private String level;

    @ApiModelProperty("输出")
    private String output;

    private Date createTime;

    public SleepInfo parseFromPo(DtrdEntEvaluationRdSleep po){
        this.setDataId(po.getDataId());
        this.setPatientId(po.getPatientId());
        ArrayList<Integer> answerList = new ArrayList<>(Evaluation.ProblemNum.SLEEP.getNum());
        String input = po.getInput();
        if (!StrUtil.isBlank(input)){
            String[] strings = input.split(",");
            for (String s : strings) {
                answerList.add(Integer.parseInt(s));
            }
        }
        this.setInput(answerList);
        this.setTotal(po.getTotal());
        this.setLevel(po.getLevel());
        this.setOutput(po.getOutput());
        this.setCreateTime(po.getCreateTime());
        return this;
    }
}
